package com.cslg.ac.demo.service.user;

import com.cslg.ac.demo.constant.ResponseCode;
import com.cslg.ac.demo.dao.user.po.team.TeamRecruitPO;
import com.cslg.ac.demo.dao.user.team.TeamRecuritDAO;
import com.cslg.ac.demo.entity.user.team.TeamRecruit;
import com.cslg.ac.demo.exception.ParamIllegalException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeamRecruitService {

    @Autowired
    TeamRecuritDAO teamRecuritDAO;


    public Integer[] selectByTeam(int teamId, int offset, int num){
        return teamRecuritDAO.selectByTeam(teamId, offset, num);
    }

    public TeamRecruit selectById(int recruitId){
        TeamRecruit recruit = new TeamRecruit();
        TeamRecruitPO teamRecruitPO = teamRecuritDAO.selectById(recruitId);
        if(teamRecruitPO == null){
            return null;
        }
        BeanUtils.copyProperties(teamRecruitPO, recruit);
        return recruit;
    }


    public int insert(TeamRecruit teamRecruit, int teamId){
        if(teamRecruit == null){
            throw new ParamIllegalException("teamRecruit为空！");
        }
        TeamRecruitPO teamRecruitPO = new TeamRecruitPO();
        BeanUtils.copyProperties(teamRecruit, teamRecruitPO);
        teamRecuritDAO.insert(teamRecruitPO);
        int recruitId = teamRecuritDAO.selectRecruitId();
        teamRecuritDAO.insertR(teamId, recruitId);
        return recruitId;
    }
}
